<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Repositories\ConfigRepo;


class ConfigController extends BaseController
{
    public $configRepo = null;

    public function _initialize()
    {
        $this->configRepo = new ConfigRepo;
    }

    public function all()
    {
        $allConfig = $this->configRepo->getAll();
        $data = [];
        foreach($allConfig as $itemConfig){
            $data[$itemConfig->name] = $itemConfig->value;
        }
        return $this->sucRes(200,$data);
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
       $group_id = $request->group_id;
       $data = $this->configRepo->getList($group_id);
       return $this->sucRes(200,$data);
    }
     /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
       $input = $request->only(['group_id','name','tip','title','value','type']);
        $this->configRepo->createConfig($input);
        return $this->sucRes();
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $input = $request->only(['app_id','broker_scale','name','secret','status','token','website','wechat_app_id','wechat_mch_id','wechat_secret_key']);
        $this->configRepo->saveAllConfig($input);
        return $this->sucRes();
    }

    public function group(Request $request)
    {
        $data['group'] = $this->configRepo->group();
        return $this->sucRes(200,$data);
    }
    public function createGroup(Request $request)
    {
        $data['group'] = $this->configRepo->group();
        return $this->sucRes(200,$data);
    }
     public function delGroup(Request $request)
    {
        $data['group'] = $this->configRepo->group();
        return $this->sucRes(200,$data);
    }
}
